#!/usr/bin/env bash
#
#    Linie - Install Internet Explorer on Linux <raghu.kb@gmail.com>
#
#    Copyright (C) 2010 Raghu Kaippully
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA


# Install IE7
log_info "Installing IE7..."

FILESDIR=${LINIE}/files/ie7

# Setup WINEPREFIX
export WINEPREFIX=${BASEDIR}/ie7
mkdir -p ${WINEPREFIX}

# Download required components
mkdir -p ${DOWNLOADDIR}

download IE7-WindowsXP-x86-enu.exe "http://download.microsoft.com/download/3/8/8/38889dc1-848c-4bf2-8335-86c573ad86d9/IE7-WindowsXP-x86-enu.exe"
cd ${DOWNLOADDIR}
error_check_and_debug "Checksum failed for IE7 installer, please retry with --clean-all option." md5sum -c ${FILESDIR}/ie7.files

# Install basic components with winetricks
for component in comctl32 comctl32.ocx gdiplus gecko msls31 msxml3 msxml4 msxml6 riched20 riched30; do
	log_info "Downloading and installing ${component}..."
	error_check_and_debug "Failed to install ${component}" winetricks -q ${component}
done

# Load the registry settings
log_info "Setting up wine registry..."
error_check_and_debug "Error setting up registry." wine regedit ${FILESDIR}/ie7.reg

# Install IE7
log_info "Installing IE7..."
wine IE7-WindowsXP-x86-enu.exe /quiet /update-no /nobackup /norestart |& debugfilter

# Simulate restart
log_info "Restarting wine..."
wineboot -k |& debugfilter

# Create shortcuts
mkdir -p ${HOME}/bin
cat > ${HOME}/bin/ie7 << EOF
#!/usr/bin/env bash
WINEPREFIX=${WINEPREFIX} wine 'C:/Program Files/Internet Explorer/iexplore.exe' &> /dev/null
EOF
chmod +x ${HOME}/bin/ie7

log_info "Installation complete. Start your IE using ${HOME}/bin/ie7"
